#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k,g;
		cin>>n>>k>>g;
		ll mid=ceil(g/2.0);
		ll lmid=mid-1;
		if(n*lmid>k*g)
		{
			cout<<k*g<<endl;
			continue;
		}
		ll sum=lmid*n;
		ll r=(k*g-sum)%g;
		if(r>=mid+1) cout<<sum-lmid+(r+lmid)%g;
		else if(r>0 && r<=mid)
		{
			cout<<sum-lmid-g+(r+lmid);
		}
		else if(r==0)
		{
			cout<<sum;
		}
		cout<<endl;
	}

	return 0;
}

